package com.domor.xxx.system.controller.monitor;

import java.util.List;

import com.domor.xxx.common.annotation.Log;
import com.domor.xxx.common.core.controller.BaseController;
import com.domor.xxx.common.core.domain.AjaxResult;
import com.domor.xxx.common.core.page.TableDataInfo;
import com.domor.xxx.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.domor.xxx.system.domain.SysOperLog;
import com.domor.xxx.system.service.SysOperLogService;

/**
 * <h3>操作日志记录</h3>
 *
 * @author liyuyang
 * @date 2020/5/6
 **/
@Controller
@RequestMapping("/monitor/operLog")
public class SysOperlogController extends BaseController {

    private String prefix = "monitor/operLog";

    @Autowired
    private SysOperLogService operLogService;

    @GetMapping()
    public String operLog() {
        return prefix + "/index";
    }

    @RequiresPermissions("monitor:operLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysOperLog operLog) {
        setOrderByAndPage();
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志")
    @RequiresPermissions("monitor:operLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        return util.exportExcel(list, "操作日志");
    }

    @RequiresPermissions("monitor:operLog:remove")
    @PostMapping("/delete")
    @ResponseBody
    public AjaxResult delete(String ids) {
        return toAjax(operLogService.deleteOperLogByIds(ids));
    }

    @GetMapping("/detail/{operId}")
    public String detail(@PathVariable("operId") Long operId, ModelMap mmap) {
        mmap.put("log", operLogService.selectOperLogById(operId));
        return prefix + "/detail";
    }

    @Log(title = "操作日志")
    @RequiresPermissions("monitor:operLog:remove")
    @PostMapping("/clean")
    @ResponseBody
    public AjaxResult clean() {
        operLogService.cleanOperLog();
        return success();
    }
}
